<?php

Class Service_model extends CI_Model {

    function auto_suggestion() {
        $this->db->select('*');
        $this->db->from('service');
		$this->db->join('service_type', 'service_type.service_type_id=service.service_type_id', 'left');
        $this->db->where('service.deleted', 'No');
        $this->db->where('service_qty >', 0);
		$this->db->order_by('service_type.service_type_name', 'asc');
		$this->db->order_by('service.service_name', 'asc');

        $query = $this->db->get();

        return $query;
    }
	
	function insert_service_order($data){
		$this->db->insert('service_order', $data);
		
		return $this->db->insert_id();
	}
	
	function insert_service_detail($data){
		$this->db->insert('service_detail', $data);
		
		return $this->db->insert_id();
	}
	
	function get_guest($resv_id) {
		$this->db->select();
		$this->db->from('reservation as r');
		$this->db->join('guest as g', 'g.guest_id=r.guest_id', 'left');
		$this->db->where('r.resv_id', $resv_id);
		
		return $this->db->get();
	}
	
	function is_cancelable($resv_id) {
		$this->db->select();
		$this->db->from('reservation_room');
		$this->db->where('resv_status !=', 'Out of Order');
		$this->db->where('resv_status !=', 'Check Out');
		$this->db->where('resv_id', $resv_id);
		$this->db->where('deleted', 'no');
		if($this->db->count_all_results() > 0){
			return true;
		}
		else {
			return false;
		}
	}

}

